<?php
class CommonClass {
	
	/**
	 * check choi null or bank
	 * @param $str
	 * @return neu chuoi null or blank retun true, nguoc lai return false
	 */
	static function nullOrBlank($str) {
		if ($str == NULL || strlen ( trim ( $str ) ) == 0) {
			return true;
		}
		return false;
	}
	/**
	 * lay payment cua he thong tu setting
	 */
	static function getPayments() {
		global $settings;
		$payments = array ();
		$paymentsT = preg_split ( '/\\s*,\\s*/', $settings ['payments'] );
		foreach ( $paymentsT as $payment ) {
			array_push ( $payments, array ('name' => $payment ) );
		}
		return $payments;
	}
	/**
	 * lay payment cua he thong tu setting voi key la ten cua cac e-current
	 */
	static function getPaymentsEcurrentKey() {
		global $settings;
		$payments = array ();
		$paymentsT = preg_split ( '/\\s*,\\s*/', $settings ['payments'] );
		foreach ( $paymentsT as $payment ) {
			array_push ( $payments, array ($payment => $payment ) );
		}
		return $payments;
	}
	/**
	 * Send an email from gmail
	 * @param $from
	 * @param $fromName
	 * @param $to
	 * @param $toName
	 * @param $user
	 * @param $password
	 * @param $subject
	 * @param $msg
	 * @return true if email sent sucessfull else fail
	 */
	static function sendMailFromGmail($from, $fromName, $to, $toName, $user, $password, $subject, $msg) {
		$mail = new PHPMailer ();
		$mail->IsSMTP ();
		$mail->SMTPAuth = true; // enable SMTP authentication
		$mail->SMTPSecure = "tls"; // sets the prefix to the server
		$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
		$mail->Port = 587; // set the SMTP port for the GMAIL server
		$mail->Username = $user; // GMAIL username
		$mail->Password = $password; // GMAIL password
		

		$mail->From = $from;
		$mail->FromName = $fromName;
		$mail->Subject = $subject;
		$mail->MsgHTML ( $msg );
		
		$mail->AddAddress ( $to, $toName );

		//to see if we return a message or a value bolean
		if (! $mail->Send ()) {
			return true;
		} else {
			return false;
		}
		$mail->ClearAddresses ();
		$mail->ClearAttachments ();
	}
	/**
	 * check $num is a number
	 * return true if $num is number else false
	 * 
	 * Enter description here ...
	 * @param unknown_type $num
	 */
	static function isNumeric($num){
		return is_numeric($num);
	} 
}
?>
